package org.xxpay.pay.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.apibase.service.IDCAlizftpayChannelService;
import org.xxpay.core.common.util.MyLog;
import org.xxpay.core.entity.PayDomain;
import org.xxpay.pay.channel.PayConfig;
import org.xxpay.pay.mq.BaseNotify4AlizftpayTradeSettleConfirm;
import org.xxpay.pay.service.CommonService;

@Service
public class DCAlizftpayChannelServiceImpl implements IDCAlizftpayChannelService {

    @Autowired private CommonService commonService;

    @Autowired
    private PayConfig payConfig;

    private static final MyLog _log = MyLog.getLog(DCAlizftpayChannelServiceImpl.class);

    @Autowired private BaseNotify4AlizftpayTradeSettleConfirm baseNotify4AlizftpayTradeSettleConfirm;

    @Override
    public void tradeSettleConfirm(String alipayTradeNo, String payOrderId) {

        //1. 初始化插入到表
        Long recordId = commonService.payAlizftSettRecordService.initWaitRecord(alipayTradeNo, payOrderId);

        //发送MQ 延时执行。
        if(recordId != null){ //初始化成功
            baseNotify4AlizftpayTradeSettleConfirm.doNotify(recordId);
        }

    }

    @Override
    public String getPayDomain() {
        PayDomain payDomain = commonService.payDomainService.getRandomPayDomain((byte)1, (byte)3);
        if(payDomain == null) return "";
        return payDomain.getDomainUrl();
    }
}
